package com.activitycode.util;



import android.content.Context;
import android.content.SharedPreferences;

public class SharedUtil {
	public final static String LOGIN = "Login";
	public final static String LOGINPASSREMEBER = "LOGINPASSREMEBER";
	public final static String LOGINAUTO = "LOGINAUTO";
	public final static String CITY = "CITY";
	public final static String DISTRICT = "DISTRICT";
	public final static String CITYLOG = "CITYLOG";
	public final static String HELPTAG = "HELPTAG";
	public final static String HOMETAG = "HOMETAG";
	public final static String COMPANYTAG = "COMPANYTAG";
	public final static String STARTAG = "STAR";
	public final static String ASSESSTAG = "ASSESS";
	public final static String XMPP_USERNAME = "XMPP_USERNAME";
	public final static String XMPP_PASSWORD = "XMPP_PASSWORD";

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveUserId(Context context, String userId) {

		SharedPreferences sp = context.getSharedPreferences(LOGIN, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("user_id", userId);
	
		editor.commit();
	}

	public static String getUserId(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGIN, 0);
		String isOpen = sp.getString("user_id", "");

		return isOpen;
	}

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void savePassStatus(Context context, boolean isOpen) {

		SharedPreferences sp = context
				.getSharedPreferences(LOGINPASSREMEBER, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("status", isOpen);

		editor.commit();
	}

	public static boolean getPassStatus(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGINPASSREMEBER, 0);
		boolean isOpen = sp.getBoolean("status", true);

		return isOpen;
	}

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveLoginAuto(Context context, boolean isOpen) {

		SharedPreferences sp = context.getSharedPreferences(LOGINAUTO, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("status", isOpen);

		editor.commit();
	}

	public static boolean getLoginAuto(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGINAUTO, 0);
		boolean isOpen = sp.getBoolean("status", true);

		return isOpen;
	}

	public static void saveXmppUserId(Context context, String userId) {

		SharedPreferences sp = context.getSharedPreferences(
				XMPP_USERNAME, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("user_id", userId);
		editor.commit();
	}

	public static String getXmppUserId(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(
				XMPP_USERNAME, 0);
		String isOpen = sp.getString("user_id", "");

		return isOpen;
	}

	public static void saveXmppUserPass(Context context, String userPass) {

		SharedPreferences sp = context.getSharedPreferences(
				XMPP_PASSWORD, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("user_pass", userPass);
		editor.commit();
	}

	public static String getXmppUserPass(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(
				XMPP_PASSWORD, 0);
		String isOpen = sp.getString("user_pass", "");

		return isOpen;
	}

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveStar(Context context, String isOpen) {

		SharedPreferences sp = context.getSharedPreferences(STARTAG, 0);
		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("star", isOpen);
		editor.commit();
	}

	public static String getStar(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(STARTAG, 0);
		String isOpen = sp.getString("star", "");

		return isOpen;
	}

	public static void saveAssess(Context context, String isOpen) {

		SharedPreferences sp = context.getSharedPreferences(ASSESSTAG, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("assess", isOpen);

		editor.commit();
	}

	public static String getAssess(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(ASSESSTAG, 0);
		String isOpen = sp.getString("assess", "");

		return isOpen;
	}

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveHome(Context context, String isOpen) {

		SharedPreferences sp = context.getSharedPreferences(HOMETAG, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("home", isOpen);

		editor.commit();
	}

	public static String getHome(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HOMETAG, 0);
		String isOpen = sp.getString("home", "");

		return isOpen;
	}

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveCompany(Context context, String isOpen) {

		SharedPreferences sp = context.getSharedPreferences(COMPANYTAG, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("company", isOpen);

		editor.commit();
	}

	public static String getCompany(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(COMPANYTAG, 0);
		String isOpen = sp.getString("company", "");

		return isOpen;
	}

	/**
	 * keep title
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveCityName(Context context, String isOpen) {

		SharedPreferences sp = context.getSharedPreferences(CITY, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("city", isOpen);

		editor.commit();
	}

	public static String getCityName(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(CITY, 0);
		String isOpen = sp.getString("city", "");

		return isOpen;
	}

	/**
	 * keep title
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveDistrictName(Context context, String isOpen) {

		SharedPreferences sp = context.getSharedPreferences(DISTRICT, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("district", isOpen);

		editor.commit();
	}

	public static String getDistrictName(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(DISTRICT, 0);
		String isOpen = sp.getString("district", "");

		return isOpen;
	}

	/**
	 * keep last
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveCityStatus(Context context, Boolean isOpen) {
		SharedPreferences sp = context.getSharedPreferences(CITYLOG, 0);
		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("open", isOpen);
		editor.commit();
	}

	public static Boolean getCityStatus(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(CITYLOG, 0);
		Boolean isOpen = sp.getBoolean("open", true);
		return isOpen;
	}

	/**
	 * keep help first
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveHelpStatus(Context context, Boolean isOpen,
			String version) {
		SharedPreferences sp = context.getSharedPreferences(HELPTAG, 0);
		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("open", isOpen);
		editor.putString("version", version);
		editor.commit();
	}

	public static Boolean getHelpStatus(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HELPTAG, 0);
		Boolean isOpen = sp.getBoolean("open", true);
		return isOpen;
	}

	public static String getHelpVersion(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HELPTAG, 0);
		String ver = sp.getString("version", "1.0.0");

		return ver;
	}

}